package com.warehouse_management.market.controller;

import com.alibaba.fastjson.JSON;
import com.sun.org.apache.xpath.internal.operations.Or;
import com.warehouse_management.config.PageModel;
import com.warehouse_management.market.model.*;
import com.warehouse_management.market.service.impl.ImplMarketOrde;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @PACKAGE_NAME: com.warehouse_management.market.controller
 * @NAME: MarketController
 * @USER: WanWenCheng
 * @DATE: 2022/10/2
 * @TIME: 18:49
 * @Description: Market控制层(营销)
 *
 */
@Controller
@RequestMapping("/orde")
public class MarketOrdeController {

    @Autowired
    private ImplMarketOrde marketOrde;

    public ImplMarketOrde getMarketOrde() {
        return marketOrde;
    }

    public void setMarketOrde(ImplMarketOrde marketOrde) {
        this.marketOrde = marketOrde;
    }

    /*
     *
     * @PACKAGE_NAME: com.warehouse_management.market.controller
     * @NAME: queryAllMarket
     * @USER: WanWenCheng
     * @DATE: 2022/10/2
     * @TIME: 23：35
     * @Description: 分页查询
     * */
    @RequestMapping("/PageOrde")
    @ResponseBody
    public String PageOrde(Orde orde, PageModel pageModel){
        PageModel<Orde> pageModel1 = marketOrde.PageOrde(orde, pageModel);
        if (pageModel1.getData()!=null){
            if (!pageModel1.getData().isEmpty()){
                return JSON.toJSONString(pageModel1);
            }
        }
        return null;
    }

    /*
     *
     * @PACKAGE_NAME: com.warehouse_management.market.controller
     * @NAME: queryAllMarket
     * @USER: WanWenCheng
     * @DATE: 2022/10/2
     * @TIME: 23：35
     * @Description: 查询单个订单详情
     * */
    @RequestMapping("/queryOneOrde/{orderid}")
    public String queryOneCustom(@PathVariable("orderid") String orderid, HttpSession session){
        Orde condition=new Orde();
        condition.setOrderid(orderid);
        session.setAttribute("oneOrder",condition);
        return "market/order/orderView";
    }

    @RequestMapping("/ordeView")
    @ResponseBody
    public String ordeView(HttpSession session){
        Orde oneOrder = (Orde) session.getAttribute("oneOrder");
        Orde orde = marketOrde.queryOneOrde(oneOrder);
        if (orde!=null){
            return JSON.toJSONString(orde);
        }else {
            return JSON.toJSONString("false");
        }
    }

    /*
     *
     * @PACKAGE_NAME: com.warehouse_management.market.controller
     * @NAME: queryAllMarket
     * @USER: WanWenCheng
     * @DATE: 2022/10/2
     * @TIME: 23：35
     * @Description: 查询单个订单商品详情
     * */
    @RequestMapping("/queryOneOrderDetails/{orderid}")
    @ResponseBody
    public String queryOneOrderDetails(@PathVariable("orderid") String orderid){
        Orderdetails orde=new Orderdetails();
        orde.setOrderId(orderid);
        List<Orderdetails> orderdetails = marketOrde.queryOneOrderDetails(orde);
        if (orderdetails!=null){
            if (!orderdetails.isEmpty()){
                return JSON.toJSONString(orderdetails);
            }
        }
        return null;
    }

    /*
     *
     * @PACKAGE_NAME: com.warehouse_management.market.controller
     * @NAME: queryAllMarket
     * @USER: WanWenCheng
     * @DATE: 2022/10/2
     * @TIME: 23：35
     * @Description: 根据条件查询订单
     * */
    @RequestMapping("/queryOrdeByCondition")
    @ResponseBody
    public String queryOrdeByCondition(OrdeCondition condition){
        List<Orde> ordeList = marketOrde.queryOrdeByCondition(condition);
        if (ordeList!=null){
            if (!ordeList.isEmpty()){
                return JSON.toJSONString(ordeList);
            }
        }
        return JSON.toJSONString("null");
    }

    /*
     *
     * @PACKAGE_NAME: com.warehouse_management.market.controller
     * @NAME: queryAllMarket
     * @USER: WanWenCheng
     * @DATE: 2022/10/2
     * @TIME: 23：35
     * @Description: 审核订单
     * */
    @RequestMapping("/huoquId/{orderid}")
    public String huoquId(@PathVariable("orderid") String orderid, HttpSession session){
        Orde condition=new Orde();
        condition.setOrderid(orderid);
        session.setAttribute("huoID",condition);
        return "market/orderExamine/orderExamine";
    }

    @RequestMapping("/shenheView")
    @ResponseBody
    public String shenheView(HttpSession session){
        Orde huoID = (Orde) session.getAttribute("huoID");
        Orde orde = marketOrde.queryOneOrde(huoID);
        if (orde!=null){
            return JSON.toJSONString(orde);
        }else {
            return JSON.toJSONString("false");
        }
    }

    /*
     *
     * @PACKAGE_NAME: com.warehouse_management.market.controller
     * @NAME: queryAllMarket
     * @USER: WanWenCheng
     * @DATE: 2022/10/2
     * @TIME: 23：35
     * @Description: 更新审核意见
     * */
    @RequestMapping("/updateSuggest")
    @ResponseBody
    public String updateSuggest(Orde orde){
        int i = marketOrde.updateSuggest(orde);
        if (i>0){
            return JSON.toJSONString("true");
        }else {
            return JSON.toJSONString("false");
        }
    }

}
